package haitao.numberpicker.city;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import haitao.dialog.view.AlertChooser;
import haitao.dialog.view.AlertDialog;
import haitao.dialog.view.MaterialDialog;
import haitao.library.dialog.eaxmple.R;

public class MainActivity extends Activity {

	private Button show_dialog;
	private Button show_btn;
	private Button show_alert;
	private Button show_alertios;
	MaterialDialog mMaterialDialog;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		show_dialog =(Button) findViewById(R.id.show_dialog);
		show_btn  =(Button) findViewById(R.id.show_md);
		show_alert  =(Button) findViewById(R.id.show_alert);
		show_alertios  =(Button) findViewById(R.id.show_alertios);
		mMaterialDialog = new MaterialDialog(this);
		show_dialog.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Dialog dialog = null;
				AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this).setTitle(null).setMessage("删除 --不可撤销").setNegativeButton("取消", null)
						.setPositiveButton("确定", new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface arg0, int arg1) {
								// delete();
							}
						});
				builder.setMinMsgHeight(120);
				//builder.setMsgGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
				dialog = builder.create();
				dialog.show();
			}
		});
		show_btn.setOnClickListener( new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				if (mMaterialDialog != null) {
					mMaterialDialog.setTitle("MaterialDialog")
							.setMessage(
									"Hi! This is a MaterialDialog. It's very easy to use, you just new and show() it " +
											"then the beautiful AlertDialog will show automatedly. It is artistic, conforms to Google Material Design." +
											" I hope that you will like it, and enjoy it. ^ ^"
							)
							//mMaterialDialog.setBackgroundResource(R.drawable.background);
							.setPositiveButton(
									"OK", new View.OnClickListener() {
										@Override
										public void onClick(View v) {
											mMaterialDialog.dismiss();
											Toast.makeText(MainActivity.this, "Ok", Toast.LENGTH_LONG).show();

										}
									}
							)
							.setNegativeButton(
									"CANCLE", new View.OnClickListener() {
										@Override
										public void onClick(View v) {
											mMaterialDialog.dismiss();
											Toast.makeText(MainActivity.this, "Cancle", Toast.LENGTH_LONG).show();
										}
									}
							)
							.setCanceledOnTouchOutside(false)
							// You can change the message anytime.
							// mMaterialDialog.setTitle("提示");
							.setOnDismissListener(
									new DialogInterface.OnDismissListener() {
										@Override
										public void onDismiss(DialogInterface dialog) {
											Toast.makeText(MainActivity.this, "onDismiss", Toast.LENGTH_SHORT).show();
										}
									}
							)
							.show();
					// You can change the message anytime.
					// mMaterialDialog.setMessage("嗨！这是一个 MaterialDialog. 它非常方便使用，你只需将它实例化，这个美观的对话框便会自动地显示出来。它简洁小巧，完全遵照 Google 2014 年发布的 Material Design 风格，希望你能喜欢它！^ ^");
				} else {
					Toast.makeText(getApplicationContext(), "You should init firstly!", Toast.LENGTH_SHORT).show();
				}
			}
		});
		show_alert.setOnClickListener( new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				showAlertChooser();
			}
		});



		show_alertios.setOnClickListener( new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				showAlertChooser();
			}
		});
	}

	//图片选择
	private void showAlertChooser() {
		new AlertChooser.Builder(this).setTitle("选择图片").addItem("相机", new AlertChooser.OnItemClickListener() {
			@Override
			public void OnItemClick(AlertChooser chooser) {
				chooser.dismiss();
			}
		}).addItem("相册", new AlertChooser.OnItemClickListener() {
			@Override
			public void OnItemClick(AlertChooser chooser) {
				chooser.dismiss();
			}
		}).setNegativeItem("取消", new AlertChooser.OnItemClickListener() {
			@Override
			public void OnItemClick(AlertChooser chooser) {
				chooser.dismiss();
			}
		}).show();
	}

}
